package com.yxq.mdt.app.modules.personal.ui.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.orhanobut.hawk.Hawk;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseFragment;
import com.yxq.mdt.app.constant.SPKey;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.auction.bean.SendGoodsNum;
import com.yxq.mdt.app.modules.auction.ui.AuctionMyTeamAc;
import com.yxq.mdt.app.modules.auction.ui.AuctionProfitAc;
import com.yxq.mdt.app.modules.main.bean.NameAndPhoneBean;
import com.yxq.mdt.app.modules.main.ui.MainActivity;
import com.yxq.mdt.app.modules.order.ui.OrderListTabActivity;
import com.yxq.mdt.app.modules.personal.adapter.MainAuctionListAdapter;
import com.yxq.mdt.app.modules.personal.adapter.MainPersonalListAdapter;
import com.yxq.mdt.app.modules.personal.bean.MainPersonTokenBean;
import com.yxq.mdt.app.modules.personal.bean.MainPersonalAuctionBean;
import com.yxq.mdt.app.modules.personal.bean.MainPersonalBean;
import com.yxq.mdt.app.modules.personal.bean.MainPersonalImNumber;
import com.yxq.mdt.app.modules.personal.bean.MyPersonalBean;
import com.yxq.mdt.app.modules.personal.bean.RechargeRecordBean;
import com.yxq.mdt.app.modules.personal.bean.UserIndexBean;
import com.yxq.mdt.app.modules.personal.model.AddressModel;
import com.yxq.mdt.app.modules.personal.model.MainPersonalModel;
import com.yxq.mdt.app.modules.personal.presenter.IMainPersonalContract;
import com.yxq.mdt.app.modules.personal.presenter.MainPersonalPresenter;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalAnchorAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalBrowsingHistoryAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalConcernListAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalCustomerServiceAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalDenseBrickAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalFansListAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalFriendListAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalMyCircleAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalMyCollectAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalMyFootprintAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalMyPublishAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalSettingsAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalShippingAddressAc;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalSugarListAc;
import com.yxq.mdt.app.modules.shoppingcart.ui.CartActivity;
import com.yxq.mdt.app.modules.socialcontact.ui.activity.SocialPersonalHomepageAc;
import com.yxq.mdt.app.modules.spikeorder.ui.SpikeOrderListTabActivity;
import com.yxq.mdt.app.modules.splash.model.SplashModel;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.modules.webview.ui.MiWebViewActivity;
import com.yxq.mdt.app.widgets.CircleImageView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static android.app.Activity.RESULT_OK;

/**
 * 我的
 */
public class MainPersonalFragment extends BaseFragment<MainPersonalPresenter> implements IMainPersonalContract.View {

    @BindView(R.id.personal_go_to_settings)
    ImageView personalGoToSettings;
    @BindView(R.id.personal_nike_name)
    TextView personalNikeName;
    @BindView(R.id.personal_sex_image)
    ImageView personalSexImage;
    @BindView(R.id.personal_id_number)
    TextView personalIdNumber;
    @BindView(R.id.personal_attention_number)
    TextView personalAttentionNumber;
    @BindView(R.id.personal_fans_number)
    TextView personalFansNumber;
    @BindView(R.id.personal_friend_number)
    TextView personalFriendNumber;
    @BindView(R.id.personal_nike_img)
    CircleImageView personalNikeImg;
    @BindView(R.id.personal_nike_type)
    Button personalNikeType;
    @BindView(R.id.personal_sugar_number)
    TextView personalSugarNumber;
    @BindView(R.id.personal_integral_number)
    TextView personalIntegralNumber;
    @BindView(R.id.personal_masonry_number)
    TextView personalMasonryNumber;
    @BindView(R.id.personal_my_order)
    LinearLayout personalMyOrder;
    @BindView(R.id.personal_obligation)
    LinearLayout personalObligation;
    @BindView(R.id.personal_to_send)
    LinearLayout personalToSend;
    @BindView(R.id.personal_receiving)
    LinearLayout personalReceiving;
    @BindView(R.id.personal_stocks)
    LinearLayout personalStocks;
    @BindView(R.id.personal_after_sale)
    LinearLayout personalAfterSale;
    @BindView(R.id.personal_list_recycler)
    RecyclerView personalListRecycler;
    MainPersonalListAdapter mainPersonalListAdapter;
    MainAuctionListAdapter mainAuctionListAdapter;
    @BindView(R.id.personal_nike_lint)
    RelativeLayout personalNikeLint;
    @BindView(R.id.me_tv_unread_0)
    TextView meTvUnread0;
    @BindView(R.id.me_tv_unread_1)
    TextView meTvUnread1;
    @BindView(R.id.me_tv_unread_2)
    TextView meTvUnread2;
    @BindView(R.id.me_tv_unread_3)
    TextView meTvUnread3;
    @BindView(R.id.me_tv_unread_4)
    TextView meTvUnread4;
    @BindView(R.id.personal_go_to_shopping)
    LinearLayout personalGoToShopping;
    @BindView(R.id.personal_tv_attention_number)
    TextView personalTvAttentionNumber;
    @BindView(R.id.personal_layout_attention_number)
    RelativeLayout personalLayoutAttentionNumber;
    @BindView(R.id.personal_tv_fans_number)
    TextView personalTvFansNumber;
    @BindView(R.id.personal_layout_fans_number)
    RelativeLayout personalLayoutFansNumber;
    @BindView(R.id.main_mine_layout_order_my)
    RelativeLayout mainMineLayoutOrderMy;
    @BindView(R.id.personal_auction_my_profit)
    LinearLayout personalAuctionMyProfit;
    @BindView(R.id.personal_auction_my_team)
    LinearLayout personalAuctionMyTeam;
    @BindView(R.id.personal_auction_recycler)
    RecyclerView personalAuctionRecycler;
    @BindView(R.id.is_auction_show)
    LinearLayout isAuctionShow;
    private List<MainPersonalBean> mainPersonalBeans;
    private List<MainPersonalAuctionBean> mainPersonalAuctionBeans;
    private static final int REGIST_WHAT_FAILE = 1;
    private static final int REGIST_WHAT_SUCCESS = 0;
    private static final int LOGIN_WHAT_SUCCESS = 2;
    private static final int LOGIN_WHAT_FAIL = 3;
    private static final int ACTION_QUEST_CODE_ORDER = 10086;
    String userId = "";
    int number;

    @Override
    protected int attachLayoutId() {
        return R.layout.main_personal_fragment_layout;
    }

    @Override
    protected MainPersonalPresenter getPresenter() {
        return new MainPersonalPresenter(this, new MainPersonalModel());
    }

    @Override
    public void initView(View view) {
        GridLayoutManager recyclerViewLayoutManager = new GridLayoutManager(mContext, 4);
        GridLayoutManager recyclerAuctionManager = new GridLayoutManager(mContext, 3);
        personalAuctionRecycler.setLayoutManager(recyclerAuctionManager);
        personalListRecycler.setLayoutManager(recyclerViewLayoutManager);
        mainPersonalBeans = new ArrayList<>();
        initAddData();
        mainPersonalListAdapter = new MainPersonalListAdapter(mainPersonalBeans);
        personalListRecycler.setAdapter(mainPersonalListAdapter);
        mainPersonalListAdapter.setOnItemClickListener((adapter, view1, position) -> {
            switch (position) {
                case 0:
                    //我的圈子
                    intentAc(MainPersonalMyCircleAc.class);
                    break;
                case 1:
                    //我的发表
                    intentAc(MainPersonalMyPublishAc.class);
                    break;
                case 2:
                    //我的收藏
                    intentAc(MainPersonalMyCollectAc.class);
                    break;
                case 3:
                    //收货地址
                    intentAc(MainPersonalShippingAddressAc.class);
                    break;
                case 4:
                    //我的足迹
                    intentAc(MainPersonalMyFootprintAc.class);
                    break;
                case 5:
                    //谁看过我
                    intentAc(MainPersonalBrowsingHistoryAc.class);
                    break;
                case 6:
                    //联系客服
                    intentAc(MainPersonalCustomerServiceAc.class);
                    break;
                case 7:
//                    //密聊中心
//                    intentAc(MainPersonalAnchorAc.class);
//                    break;
//                case 8:
                    //秒杀
                    intentAc(SpikeOrderListTabActivity.class);
                    break;
                default:
            }
        });
        setPMViewVisible();
    }

    /**
     * 设置拍卖相关入口是否显示
     */
    private void setPMViewVisible() {
        NameAndPhoneBean nameAndPhoneBean = Hawk.get(SPKey.SP_KEY_NAME_PHONE_INFO);
        //判断礼包是否显示
        if (nameAndPhoneBean != null && nameAndPhoneBean.getPmSetting() != null && nameAndPhoneBean.getPmSetting().getIs_show() == 1) {
            isAuctionShow.setVisibility(View.VISIBLE);
        } else {
            isAuctionShow.setVisibility(View.GONE);
        }
    }

    @Override
    public void initData() {
        mPresenter = new MainPersonalPresenter(this, new MainPersonalModel());
        loadCache();
        //查询个人资料
        mPresenter.getPersonalMyData();
        mPresenter.selectByOrderSendGoodsNum();
        SplashModel.getNameAndPhone(new ApiModel.CommonCallback<NameAndPhoneBean>() {
            @Override
            public void onSuccess(NameAndPhoneBean nameAndPhoneBean) {
                if (nameAndPhoneBean != null) {
                    Hawk.delete(SPKey.SP_KEY_NAME_PHONE_INFO);
                    Hawk.put(SPKey.SP_KEY_NAME_PHONE_INFO, nameAndPhoneBean);
                }
            }

            @Override
            public void onError(String errMsg) {
                showCenterToast(errMsg);
            }
        });
    }

    /**
     * 预加载缓存数据
     */
    private void loadCache() {
        MyPersonalBean myPersonalBean = Hawk.get(SPKey.SP_KEY_USER_MY_INFO, null);
        if (myPersonalBean != null) {
            initPersonalData(myPersonalBean);
        }
    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            refresh();
        }
    }

    private void refresh() {
        mPresenter.getPersonalMyData();
        mPresenter.selectByOrderSendGoodsNum();
        AddressModel.userIndex(new ApiModel.CommonCallback<UserIndexBean>() {
            @Override
            public void onSuccess(UserIndexBean userIndexBean) {
                if (userIndexBean != null && userIndexBean.getOrder_count() != null) {

                    if (userIndexBean.getOrder_count().getStatus_0() > 0) {
                        meTvUnread0.setVisibility(View.VISIBLE);
                        meTvUnread0.setText(userIndexBean.getOrder_count().getStatus_0() + "");
                    } else {
                        meTvUnread0.setVisibility(View.GONE);
                    }

                    if (userIndexBean.getOrder_count().getStatus_1() > 0) {
                        meTvUnread1.setVisibility(View.VISIBLE);
                        meTvUnread1.setText(userIndexBean.getOrder_count().getStatus_1() + "");
                    } else {
                        meTvUnread1.setVisibility(View.GONE);
                    }
                    if (userIndexBean.getOrder_count().getStatus_2() > 0) {
                        meTvUnread2.setVisibility(View.VISIBLE);
                        meTvUnread2.setText(userIndexBean.getOrder_count().getStatus_2() + "");
                    } else {
                        meTvUnread2.setVisibility(View.GONE);
                    }
//                    if (userIndexBean.getOrder_count().getStatus_3() > 0) {
//                        meTvUnread3.setVisibility(View.VISIBLE);
//                        meTvUnread3.setText(userIndexBean.getOrder_count().getStatus_3() + "");
//                    } else {
//                        meTvUnread3.setVisibility(View.GONE);
//                    }
                    if (userIndexBean.getOrder_count().getStatus_4() > 0) {
                        meTvUnread4.setVisibility(View.VISIBLE);
                        meTvUnread4.setText(userIndexBean.getOrder_count().getStatus_4() + "");
                    } else {
                        meTvUnread4.setVisibility(View.GONE);
                    }

                }
            }

            @Override
            public void onError(String errMsg) {

            }
        });
        SplashModel.getNameAndPhone(new ApiModel.CommonCallback<NameAndPhoneBean>() {
            @Override
            public void onSuccess(NameAndPhoneBean nameAndPhoneBean) {
                if (nameAndPhoneBean != null) {
                    Hawk.delete(SPKey.SP_KEY_NAME_PHONE_INFO);
                    Hawk.put(SPKey.SP_KEY_NAME_PHONE_INFO, nameAndPhoneBean);
                }
            }

            @Override
            public void onError(String errMsg) {
                showCenterToast(errMsg);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        if (isVisible()) {
            refresh();
        }
    }

    //添加其它工具数据
    private void initAddData() {
        MainPersonalBean mainPersonalBean;
        mainPersonalBean = new MainPersonalBean("我的圈子", R.mipmap.icon_personal_circle);
        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("我的发表", R.mipmap.list);
        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("我的收藏", R.mipmap.icon_personal_collection);
        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("收货地址", R.mipmap.icon_personal_address);
        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("我的足迹", R.mipmap.icon_personal_footprint);
        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("谁看过我", R.mipmap.icon_personal_read_me);
        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("客服中心", R.mipmap.icon_personal_customer_service);
        mainPersonalBeans.add(mainPersonalBean);
//        mainPersonalBean = new MainPersonalBean("密聊中心", R.mipmap.icon_personal_anchor_center);
//        mainPersonalBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalBean("秒杀订单", R.mipmap.icon_personal_seckill);
        mainPersonalBeans.add(mainPersonalBean);
    }

    @OnClick({R.id.main_mine_layout_order_my, R.id.personal_go_to_shopping, R.id.personal_go_to_settings, R.id.personal_nike_name, R.id.personal_sex_image, R.id.personal_id_number, R.id.personal_layout_attention_number, R.id.personal_layout_fans_number, R.id.personal_friend_number, R.id.personal_nike_img, R.id.personal_nike_type, R.id.personal_sugar_number, R.id.personal_integral_number, R.id.personal_masonry_number, R.id.personal_my_order, R.id.personal_obligation, R.id.personal_to_send, R.id.personal_receiving, R.id.personal_stocks, R.id.personal_after_sale, R.id.personal_auction_my_profit, R.id.personal_auction_my_team})
    public void onClick(View view) {
        switch (view.getId()) {
            //去往购物车
            case R.id.personal_go_to_shopping:
                Intent intent = new Intent(mContext, CartActivity.class);
                startActivity(intent);
                break;
            //去往设置界面
            case R.id.personal_go_to_settings:
                intentAc(MainPersonalSettingsAc.class);
                break;
            //修改个人资料
            case R.id.personal_nike_name:
            case R.id.personal_sex_image:
            case R.id.personal_id_number:
            case R.id.personal_nike_img:
                Intent it = new Intent(mContext, SocialPersonalHomepageAc.class);
                it.putExtra("userId", userId);
                mContext.startActivity(it);
                break;
            //我的关注
            case R.id.personal_layout_attention_number:
                intentAc(MainPersonalConcernListAc.class);
                break;
            //我的粉丝
            case R.id.personal_layout_fans_number:
                intentAc(MainPersonalFansListAc.class);
                break;
            //我的好友
            case R.id.personal_friend_number:
                intentAc(MainPersonalFriendListAc.class);
                break;
            //用户角色
            case R.id.personal_nike_type:
                break;
            //蜜豆详情列表
            case R.id.personal_sugar_number:
                intentAc(MainPersonalSugarListAc.class);
                break;
            //积分详情列表
            case R.id.personal_integral_number:
                //intentAc(MainPersonalIntegrationListAc.class);
                break;
            //蜜砖详情列表
            case R.id.personal_masonry_number:
                intentAc(MainPersonalDenseBrickAc.class);
                break;
            //全部订单
            case R.id.main_mine_layout_order_my:
            case R.id.personal_my_order:
                intent = new Intent(mContext, OrderListTabActivity.class);
                intent.putExtra("tab", 0);
                startActivityForResult(intent, ACTION_QUEST_CODE_ORDER);
                break;
            //待付款
            case R.id.personal_obligation:
                intent = new Intent(mContext, OrderListTabActivity.class);
                intent.putExtra("tab", 1);
                startActivityForResult(intent, ACTION_QUEST_CODE_ORDER);
                break;
            //待发货
            case R.id.personal_to_send:
                intent = new Intent(mContext, OrderListTabActivity.class);
                intent.putExtra("tab", 2);
                startActivityForResult(intent, ACTION_QUEST_CODE_ORDER);
                break;
            //待收货
            case R.id.personal_receiving:
                intent = new Intent(mContext, OrderListTabActivity.class);
                intent.putExtra("tab", 3);
                startActivityForResult(intent, ACTION_QUEST_CODE_ORDER);
                break;
            //已完成
            case R.id.personal_stocks:
                intent = new Intent(mContext, OrderListTabActivity.class);
                intent.putExtra("tab", 4);
                startActivityForResult(intent, ACTION_QUEST_CODE_ORDER);
                break;
            //售后
            case R.id.personal_after_sale:
                intent = new Intent(mContext, OrderListTabActivity.class);
                intent.putExtra("tab", 5);
                startActivityForResult(intent, ACTION_QUEST_CODE_ORDER);
                break;
            //我的团队
            case R.id.personal_auction_my_team:
                intentAc(AuctionMyTeamAc.class);
                break;
            //我的收益
            case R.id.personal_auction_my_profit:
                intentAc(AuctionProfitAc.class);
                break;
            default:
        }
    }

    //一般不带参数的跳转activity
    public void intentAc(Class<?> cls) {
        Intent intent = new Intent(getActivity(), cls);
        startActivity(intent);
    }

    @Override
    public void onLoadSuccess(MyPersonalBean myPersonalBean) {
        if (myPersonalBean == null) {
            return;
        }
        Hawk.delete(SPKey.SP_KEY_USER_MY_INFO);
        Hawk.put(SPKey.SP_KEY_USER_MY_INFO, myPersonalBean);
        if (!isDetached()) {
            initPersonalData(myPersonalBean);
        }
    }

    @Override
    public void onLoadPersonalDataFailed() {

    }

    @Override
    public void onLoadPersonalTokenSuccess(MainPersonTokenBean mainPersonTokenBean) {
    }

    @Override
    public void onLoadPersonalTokenFailed() {

    }

    @Override
    public void onLoadImNumberFailed() {

    }

    @Override
    public void onLoadImNumberSuccess(MainPersonalImNumber mainPersonalImNumber) {
    }

    @Override
    public void onLoadAddSaveFailed() {

    }

    @Override
    public void onLoadAddSaveSuccess(MainPersonalImNumber mainSaveAddImNumber) {
        mPresenter.getOnLoadImNumber();
    }

    @Override
    public void onGsGiveFailed() {

    }

    @Override
    public void onGsGiveSuccess(RechargeRecordBean rechargeRecordBean) {

    }

    @Override
    public void inSelectByOrderSendGoodsNumSuccess(SendGoodsNum sendGoodsNum) {
        MainPersonalAuctionBean mainPersonalBean;
        number = sendGoodsNum.getNumber();
        mainPersonalAuctionBeans = new ArrayList<>();
        //添加拍卖数据
        mainPersonalBean = new MainPersonalAuctionBean("我发起的活动", R.mipmap.icon_personal_launch, 0);
        mainPersonalAuctionBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalAuctionBean("我参与的活动", R.mipmap.icon_personal_participate, 0);
        mainPersonalAuctionBeans.add(mainPersonalBean);
        mainPersonalBean = new MainPersonalAuctionBean("活动订单", R.mipmap.icon_personal_order, number);
        mainPersonalAuctionBeans.add(mainPersonalBean);
        mainAuctionListAdapter = new MainAuctionListAdapter(mainPersonalAuctionBeans);
        personalAuctionRecycler.setAdapter(mainAuctionListAdapter);

        mainAuctionListAdapter.setOnItemClickListener((adapter, view12, position) -> {
            NameAndPhoneBean nameAndPhoneBean = Hawk.get(SPKey.SP_KEY_NAME_PHONE_INFO);
            //拍卖相关跳转 是否显示
            if (nameAndPhoneBean != null && nameAndPhoneBean.getPmSetting() != null && nameAndPhoneBean.getPmSetting().getIs_show() == 1) {
                switch (position) {
                    case 0://我发起
                        Intent intent = new Intent(getActivity(), MiWebViewActivity.class);
                        intent.putExtra("url", nameAndPhoneBean.getPmSetting().getPm_sponsor_url());
                        startActivity(intent);
                        break;
                    case 1://我参与
                        intent = new Intent(getActivity(), MiWebViewActivity.class);
                        intent.putExtra("url", nameAndPhoneBean.getPmSetting().getPm_join_url());
                        startActivity(intent);
                        break;
                    case 2://订单
                        intent = new Intent(getActivity(), MiWebViewActivity.class);
                        intent.putExtra("url", nameAndPhoneBean.getPmSetting().getOrder_url());
                        startActivity(intent);
                        break;
                    default:
                }
            }
        });
    }

    @Override
    public void inSelectByOrderSendGoodsNumFailed() {

    }

    /**
     * 显示个人资料
     *
     * @param myPersonalBean
     */
    private void initPersonalData(MyPersonalBean myPersonalBean) {
        if (mContext == null) {
            return;
        }
        userId = String.valueOf(myPersonalBean.getUserId());
        //头像
        GlideHelper.setLoadImage(mContext, myPersonalBean.getHeadimg(), R.mipmap.head_icon, personalNikeImg);
        //性别
        switch (myPersonalBean.getSex()) {
            case 1:
                personalSexImage.setImageResource(R.mipmap.xb_nan);
                break;
            case 2:
                personalSexImage.setImageResource(R.mipmap.xb_nv);
                break;
            default:
        }
        personalIdNumber.setText("蜜豆号" + myPersonalBean.getId());
        personalFansNumber.setText(String.valueOf(myPersonalBean.getRelationFs()));
        personalAttentionNumber.setText(String.valueOf(myPersonalBean.getRelationGz()));
        if (myPersonalBean != null && myPersonalBean.getGsName() == null) {
            personalNikeName.setText("");
        } else {
            personalNikeName.setText(myPersonalBean.getGsName());
        }
        personalSugarNumber.setText(parseMoney(myPersonalBean.getMoney()));
        personalIntegralNumber.setText(String.format("积分：%d", myPersonalBean.getIntegral()));
        personalMasonryNumber.setText(parseHoneyDrill(myPersonalBean.getHoneyDrill()));
    }

    /**
     * 格式化蜜豆显示
     *
     * @param money
     * @return
     */
    private String parseMoney(float money) {
//        if (money == 0f && money < 1000f) {
//            return "蜜豆:" + money;
//        } else if (money >= 1000f && money < 10000f) {
//            return String.format("蜜豆:%.1fk", (money / 1000f));
//        } else if (money >= 10000f) {
//            return String.format("蜜豆:%.1fw", (money / 10000f));
//        }
        return String.format("蜜豆:%.2f", money);
    }

    private String parseHoneyDrill(float money) {
//        if (money == 0 && money < 1000) {
//            return "蜜钻:" + money;
//        } else if (money >= 1000 && money < 10000) {
//            return String.format("蜜钻:%.1fk", (money / 1000f));
//        } else if (money >= 10000) {
//            return String.format("蜜钻:%.1fw", (money / 10000f));
//        }
        return String.format("蜜钻:%.2f", money);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK == resultCode) {
            if (requestCode == ACTION_QUEST_CODE_ORDER) {
                MainActivity mainActivity = (MainActivity) getActivity();
                //跳转商城页面
                mainActivity.selectItem(R.id.nav_item_mall);
            }
        }
    }
}

